package login;
import java.awt.Dimension; 
import java.awt.Image;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.*;
import javax.swing.text.BadLocationException;
 public class MioLogin extends JFrame implements ActionListener{
	 
	 private static JButton Entra=new JButton("Entra");
	    final JTextField user_tf = new JTextField();
	    final JPasswordField pass_tf = new JPasswordField();
	    static JDialog frame;
	    private static String usr = "user";
	    private static String psw = "password";
	    
	  
		public MioLogin() {
	        frame = new JDialog();
	        frame.setModal(true);
	        frame.setLocation(350, 150);
	        frame.setTitle("LOGIN");
			 frame.setSize(700,400);
			 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			 ImagePanell panel= new ImagePanell   (new ImageIcon("C:\\Users\\acer\\workspace1\\LaboratorioDiAlgoritmi\\src\\Image\\images-4.jpg").getImage());
		   	 frame.getRootPane().add(panel);
	 
	        // pannello
	        panel.setSize(new Dimension(700,400));
	        panel.setMaximumSize(new Dimension(700,400));
	        panel.setMinimumSize(new Dimension(700,400));
	        panel.setPreferredSize(new Dimension(700,400));
	        panel.setLayout(null);
	 
	        // JLabel
	        JLabel user = new JLabel("Username");
	        JLabel password = new JLabel("Password");
	   
	 
	        // entra button
	        Entra.setBounds(510,265,120, 65);
	        Entra.setBorder(null);
	        Entra.addActionListener(this);
	        Entra.setFont(new Font("Impact",Font.TRUETYPE_FONT,16));
	        Entra.setForeground(new java.awt.Color(64,0,64));
	        //user,password label
	        user.setBounds(30,60, 260,80);
	        password.setBounds(30, 160, 260, 80);
	        user.setForeground(new java.awt.Color(0,0,0));
	       password.setForeground(new java.awt.Color(0,0,0));
	        // campi di inserimento
	       user_tf.setBounds(100, 80, 190, 40);
	        pass_tf.setBounds(100, 180, 190, 40);
	        // aggiungo al panello principale
	    panel.add(user);
	        panel.add(password);
	        panel.add(user_tf);
	        panel.add(pass_tf);
	        panel.add(Entra);
            frame.add(panel);
	        frame.setResizable(false);
	        frame.pack();
	        frame.setVisible(true);}
	 public static void main(String[]args){
		 
		 MioLogin f=new MioLogin();
		
		  }
						
					
		  
		
	 
	 
		   
			@Override
			//distruggi frame
				public void actionPerformed(ActionEvent ae) {
				
				if(ae.getSource()==Entra && user_tf.getText().length() <= 3 || user_tf.getText().length()>=13){
					
						
							SwingUtilities.invokeLater(new Runnable() {
								public void run() {
								Errore inst = new Errore();
									inst.setLocationRelativeTo(null);
									
							
						        }
							});
							frame.dispose();  }
				else if(ae.getSource()==Entra){
					SwingUtilities.invokeLater(new Runnable() {
						public void run() {
						PagPers inst = new PagPers();
							inst.setLocationRelativeTo(null);
							inst.setVisible(true);
					
				        }
					});
					frame.dispose();  }
				
					
				}
			
			public static Object getInstance() {
				// TODO Auto-generated method stub
				return null;
			}
			}



